{
 "cells": [
  {
   "cell_type": "raw",
   "id": "83d09dc4-7f8e-4898-8011-c3187e802920",
   "metadata": {},
   "source": [
    "test: /root/autodl-tmp/testing/image_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8fd489cb-928f-4e9d-897f-a5d300d39d6c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import cv2\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "dff970c4-3c5f-471b-b1f9-de8d307fd0f4",
   "metadata": {},
   "outputs": [],
   "source": [
    "test_path = '/root/autodl-tmp/testing/image_2' #'/root/autodl-tmp/test_img' \n",
    "model_name = 'base_s_16e'\n",
    "model = f'{model_name}.pt'\n",
    "output_path = f'../detection_results/{model_name}_yolo_result'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "30c03265-c98b-4af6-8071-20099705e512",
   "metadata": {},
   "outputs": [],
   "source": [
    "# data为之前训练用的东西的路径\n",
    "command = f\" \\\n",
    "python detect.py \\\n",
    "--data data/kitti.yaml  \\\n",
    "--weights {model}  \\\n",
    "--save-txt \\\n",
    "--project {output_path} \\\n",
    "--source {test_path} \\\n",
    "--nosave \\\n",
    "\"\n",
    "!{command}\n",
    "\n",
    "#测试集图片太多了，这里打印会卡死，还是直接在命令行弄把\n",
    "'''\n",
    "python detect.py --nosave --data data/kitti.yaml --weights base_s_16e.pt --save-txt --project ../detection_results --source /root/autodl-tmp/testing/image_2\n",
    "\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9760d66a-f36b-4cb6-975b-f62011ee956f",
   "metadata": {},
   "outputs": [],
   "source": [
    "#这个是验证集的\n",
    "# command = f\" \\\n",
    "# python val.py \\\n",
    "# --data data/kitti.yaml  \\\n",
    "# --weights {model}  \\\n",
    "# --save-txt \\\n",
    "# --img 640 \\\n",
    "# --project {output_path}\\\n",
    "# \"\n",
    "# !{command}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b17250ba-4cc6-40a3-8d87-578db5986ed5",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "039d34d3-f0b3-467b-9c43-1d1f5f722cad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[34m\u001b[1mval: \u001b[0mdata=data/kitti.yaml, weights=['base_s_16e.pt'], batch_size=32, imgsz=640, conf_thres=0.001, iou_thres=0.6, max_det=300, task=test, device=, workers=8, single_cls=False, augment=False, verbose=False, save_txt=False, save_hybrid=False, save_conf=False, save_json=False, project=runs/val, name=exp, exist_ok=False, half=False, dnn=False\n",
      "YOLOv5 🚀 2bde9db5 Python-3.10.8 torch-2.1.2+cu118 CUDA:0 (NVIDIA GeForce RTX 3080, 20181MiB)\n",
      "\n",
      "Fusing layers... \n",
      "YOLOv5s_kitti summary: 157 layers, 7031701 parameters, 0 gradients, 15.8 GFLOPs\n",
      "\u001b[34m\u001b[1mtest: \u001b[0mScanning /root/autodl-tmp/datasets/kitti/labels/test... 2244 images, 0 bac\u001b[0m\n",
      "\u001b[34m\u001b[1mtest: \u001b[0mNew cache created: /root/autodl-tmp/datasets/kitti/labels/test.cache\n",
      "                 Class     Images  Instances          P          R      mAP50   \n",
      "                   all       2244      12198      0.846      0.737       0.81      0.509\n",
      "                   Car       2244       8711      0.908      0.867      0.939      0.679\n",
      "                   Van       2244        861       0.84      0.739      0.854      0.595\n",
      "                 Truck       2244        333      0.914      0.892      0.937      0.683\n",
      "                  Tram       2244        138       0.85      0.899      0.938      0.579\n",
      "            Pedestrian       2244       1286      0.865      0.651       0.75      0.386\n",
      "        Person_sitting       2244         89      0.702      0.506      0.544      0.282\n",
      "               Cyclist       2244        496      0.882      0.694      0.789      0.421\n",
      "                  Misc       2244        284      0.806      0.648      0.733      0.447\n",
      "Speed: 0.1ms pre-process, 1.2ms inference, 0.9ms NMS per image at shape (32, 3, 640, 640)\n",
      "Results saved to \u001b[1mruns/val/exp\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "# data为之前训练用的东西的路径\n",
    "command_test = f\" \\\n",
    "python val.py \\\n",
    "--data data/kitti.yaml \\\n",
    "--weights {model} \\\n",
    "--task test \\\n",
    "\"\n",
    "!{command_test}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "45327dec-27fa-4737-8af1-ca72cab7a1a2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62bce557-8908-4615-9eef-5569ce5a8199",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
